package com.mobilad.bean;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.mobilad.model.User;
import com.mobilad.service.UserServiceImp;

@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean extends MasterBean{
	//private static final long serialVersionUID = 1L;

	private String LoginFailMsg_top;

/**
 * This method check the user login and authorization.
 * if user valid it goes to user page otherwise it shows error message
 * @return
 */
	public String login() {

		boolean success = authenticationService.login(mobNr, pwd);
		if (success){
			actualUser = userService.getUser(mobNr, pwd);
			setActualUser(actualUser);
			return "registered/user?faces-redirect=true"; // return to application but being logged now 
		}
		else{
			if(countryCode.equals("en")){
				setLoginFailMsg("Invalid mobile number or password!") ;
			}else{
				setLoginFailMsg("Ugyldig mobilnummer eller passord!") ;
			}
			return "";
		}
	}

	/**
	 * This method is used for header login value.
	 * @return
	 */
	public String userLogin_top(){
		boolean success = authenticationService.login(mobNr_top, pwd_top);
		
		if(success){
			return "registered/user?faces-redirect=true";
		}else{
			if(countryCode.equals("en")){
				setLoginFailMsg_top("Invalid mobile number or password!") ;
			}else{
				setLoginFailMsg_top("Ugyldig mobilnummer eller passord!") ;
			}
			return "";
		}
	}


	public String getLoginFailMsg_top() {
		return LoginFailMsg_top;
	}


	public void setLoginFailMsg_top(String loginFailMsg_top) {
		LoginFailMsg_top = loginFailMsg_top;
	}

	
}
